<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="lianjie.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
		<%
		request.setCharacterEncoding("UTF-8");
		String 	BookISBN = request.getParameter("BookISBN");
		out.println(BookISBN);
		int resultNum = 0;
		String sql3 ="select * from booksmassage where ISBN='"+BookISBN+"'";
		session.setAttribute("BookISBN", BookISBN);
		Statement sta = conn.createStatement();
		rs = sta.executeQuery(sql3);
		int i = 0;
		String Sname="";
		if(rs.next()){
			i = rs.getInt("surplus");
			Sname = rs.getString("name");
			out.println(Sname);
		} 
		
		session.setAttribute("Sname", Sname);
		if(i>0){
			String sql = "update booksmassage set surplus=surplus-1 where ISBN='" + BookISBN + "'";
			String sql2 = "update booksmassage set loan=loan+1 where ISBN='" + BookISBN + "'";
			try {
				resultNum = stmt.executeUpdate(sql);
				resultNum = stmt.executeUpdate(sql2);
			} catch (SQLException e) {
				out.println("错误提示：" + e.getMessage());
			} finally {
				stmt.close();
				conn.close();
			}
	   
			if (resultNum > 0) {
				out.println("恭喜您，借阅成功。");
				response.setHeader("Refresh", "1;URL=information.jsp");
			} else {
				out.println("抱歉，借阅失败。");
			}
		}else{
			out.append("剩余不足，借阅失败");
			response.setHeader("Refresh", "1;URL=jisuanji.jsp");
		}
 
	%>
</body>
</html>